//
//  KKBaseController.m
//  DoMi
//
//  Created by 康凯 on 16/10/26.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKBaseController.h"
#import "MBProgressHUD.h"
#import "AFNetworking.h"

@interface KKBaseController ()
@property(strong,nonatomic)MBProgressHUD *tip;
@end

@implementation KKBaseController

- (void)viewDidLoad {
    [super viewDidLoad];
    //状态栏高
    self.statusHeight=[[UIApplication sharedApplication] statusBarFrame].size.height;
    //导航栏高
    self.navHeight=self.navigationController.navigationBar.frame.size.height;
    
    self.topHeight=self.statusHeight+self.navHeight;
    
    NSUserDefaults *users=[NSUserDefaults standardUserDefaults];
    self.uid=[users objectForKey:@"uid"];
    self.token=[users objectForKey:@"token"];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;

}

#pragma mark 判断字符串是否为空
- (BOOL) isEmptyString:(NSString *)string {
    if (string == nil || string.length==0 || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    return NO;
}

#pragma mark toast
- (void) toast:(NSString *)str {
    MBProgressHUD *tip=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    tip.mode=MBProgressHUDModeText;
    tip.detailsLabel.text=str;
    tip.detailsLabel.font=[UIFont systemFontOfSize:14];
    [tip hideAnimated:YES afterDelay:1];
}
#pragma mark toast
- (void) toastLongText:(NSString *)str {
    MBProgressHUD *tip=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    tip.mode=MBProgressHUDModeText;
    tip.detailsLabel.text=str;
    tip.detailsLabel.font=[UIFont systemFontOfSize:16];
    [tip hideAnimated:YES afterDelay:1];
}
#pragma mark toast
- (void) longToast:(NSString *)str {
    MBProgressHUD *tip=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    tip.mode=MBProgressHUDModeText;
    tip.label.text=str;
    [tip hideAnimated:YES afterDelay:3];
}

-(void)setNavBlack{
    //禁止透明
    self.navigationController.navigationBar.translucent=NO;
    //电量颜色设置
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
    //背景颜色
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithHexString:@"#202021"];
    //标题字体颜色
    self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil];
    //返回字体颜色
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
}
-(void)setNavWhite{
    //禁止透明
    self.navigationController.navigationBar.translucent=NO;
    //电量颜色设置UIStatusBarStyleLightContent
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
    //背景颜色
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithHexString1:@"#F7F8F9"];
    //标题字体颜色
    self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName, nil];
}

-(void)showDialog{
    MBProgressHUD *tip=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.tip=tip;
    tip.label.text=LoadTitle;
}

-(void)dismissDialog{
    [self.tip hideAnimated:YES];
}

- (void)AFNetworkStatus{
    
    //1.创建网络监测者
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    
    /*枚举里面四个状态  分别对应 未知 无网络 数据 WiFi
     typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
     AFNetworkReachabilityStatusUnknown          = -1,      未知
     AFNetworkReachabilityStatusNotReachable     = 0,       无网络
     AFNetworkReachabilityStatusReachableViaWWAN = 1,       蜂窝数据网络
     AFNetworkReachabilityStatusReachableViaWiFi = 2,       WiFi
     };
     */
    
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        //在里面可以随便写事件
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
            NSLog(@"未知网络状态");
            break;
            case AFNetworkReachabilityStatusNotReachable:
            NSLog(@"无网络");
            break;
            
            case AFNetworkReachabilityStatusReachableViaWWAN:
            NSLog(@"蜂窝数据网");
            break;
            
            case AFNetworkReachabilityStatusReachableViaWiFi:
            NSLog(@"WiFi网络");
            break;
            default:
            break;
        }
    }] ;
    
    [manager startMonitoring];
}

-(void)dealloc{
    KKLog(@"当前视图释放啦-----");
}


@end
